﻿using UnityEngine;

public class PlayerCrouch : PlayerBaseState {
	public PlayerCrouch(PlayerController controller, PlayerStateEnum stateName, State<PlayerStateEnum> superFSM, StateFactory<PlayerStateEnum> factory) : base(controller, stateName, superFSM, factory) {
		AddConditionToSelf(() => controller.IsTouchCeiling || controller.DownInput);


		AddNewTransition(PlayerStateEnum.Run, () => !controller.IsTouchCeiling && !controller.DownInput);
	}

	public override void Enter() {
		_controller.Velocity = new Vector2(_controller.ConfigData.CrouchSpeed * _controller.XInput, 0);
		_controller.UpColl.enabled = false;
		_controller.ChangeDir();
		_controller.PlayAnim(PlayerStateEnum.Crouch);
	}

	public override void Exit() {
		_controller.UpColl.enabled = true;
	}
}